class Solution {
public:
    int minNumberOfFrogs(string croakOfFrogs) {
        int n = croakOfFrogs.size();
        unordered_map<char, int> mymap;
        string s = croakOfFrogs;
        if (s[0] != 'c') return -1;
        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'c')
            {
                if (mymap['k'] != 0)
                {
                    mymap['k']--;
                }
                mymap['c']++;
            }
            else if (s[i] == 'r')
            {
                if (mymap['c'] == 0)
                    return -1;
                mymap['r']++;
                mymap['c']--;
            }
            else if (s[i] == 'o')
            {
                if (mymap['r'] == 0)
                    return -1;
                mymap['o']++;
                mymap['r']--;
            }
            else if (s[i] == 'a')
            {
                if (mymap['o'] == 0)
                    return -1;
                mymap['a']++;
                mymap['o']--;
            }
            else if (s[i] == 'k')
            {
                if (mymap['a'] == 0)
                    return -1;
                mymap['k']++;
                mymap['a']--;
            }
        }
        if (mymap['c'] != 0 || mymap['r'] != 0 || mymap['o'] != 0 || mymap['a'] != 0)
            return -1;
        return mymap['k'];
    }
};